package freespiritsocial.io.user.data.model.bean

import androidx.appcompat.content.res.AppCompatResources
import freespiritsocial.io.user.R
import me.hgj.jetpackmvvm.base.appContext
import java.math.RoundingMode

data class CommentPojo(
    val comment: String? = null,
    val commentId: Long? = null,
    val commentTime: Long = 0L,
    val commentUserAvatar: String? = null,
    val commentUserId: String? = null,
    val commentUserName: String? = null,
    var isLike: Boolean? = null,
    val likeCount: Int = 0,
    val replies: ArrayList<CommentPojo>? = null,
    val userName: String? = null
) {
    val likeCountStr
        get() = "${
            when {
                likeCount < 999 -> likeCount.toString()
                likeCount > 9999_900 -> "9999.9k"
                else -> "${likeCount.div(1000f).toBigDecimal().setScale(1,RoundingMode.HALF_UP)}k"
            }
        } like${if (likeCount > 1) "s" else ""}"

    val commentTimeStr
        get() = (System.currentTimeMillis().div(1000L) - (commentTime)).getFreeSpiritTime(commentTime)

    val repliesCountStr
        get() = "see ${replies?.size} replie${if (replies?.size ?: 0 > 1) "s" else ""}"

    val subComment get() = "<b>$commentUserName</b> Reply <b>$userName</b>:\n$comment"

    val likeIcon get() = AppCompatResources.getDrawable(appContext,if (isLike == true) R.mipmap.icon_like_red else R.mipmap.icon_unlike)
}